package myjava.algorithm.leetcode;

public class LengthofLastWord {
	public static int lengthOfLastWord(String s) {
		if(s.length() == 0) return 0;
		
		int result = -1;
		
		int skipEmpty = 0;
		
		for(int i= s.length() - 1;i>=0;i--)
		{
			if(s.charAt(i) == ' ') continue;
			else {
				skipEmpty = i;
				break;
			}
		}
		
		for(int i= skipEmpty;i>=0;i--)
		{
			if(s.charAt(i) != ' ') continue;
			else {
				result = i;
				break;
			}
				
		}
		
		return skipEmpty - result;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(lengthOfLastWord(""));
	}

}
